function ajax(obj) {

    var defaultObj = {
        url: "/",
        methods: "get",
        data: {}
    }

    var option = Object.assign(defaultObj, obj)

    return new Promise((resolve, reject) => {
        var str = ""
        if (option.methods.toLowerCase() == "get") {
            str = str + "?"

            for (let key in option.data) {
                str = str + key + "=" + option.data[key]
            }

            str = str + "time" + Date.now() // 防止数据缓存

        }
        let xhr = new XMLHttpRequest()


        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    let qbj = JSON.parse(xhr.response)
                    resolve(qbj)
                } else {
                    reject("失败了")
                }


            }
        }

        xhr.open(option.methods, option.url + "")
        if (option.methods.toLowerCase() == 'post') {

            xhr.setRequestHeader("Content-Type", "application/json")

            xhr.send(JSON.stringify(option.data))
        } else {
            xhr.send()
        }

    })
}